package cli;

import app.UserDef;
import comm.net.cli.Client;
import comm.net.protocol.Protocol;
import comm.utill.Errno;
import comm.utill.Param;

public class UserCli extends Client {
    protected int m_rt = Errno.ERROR;

    public int addUserInfo(Param info) {
        try {
            Protocol sendProtoclo = new Protocol();
            sendProtoclo.setCmd(UserDef.Protocol.Cmd.ADD);
            sendProtoclo.setBody(info);

            m_rt = send(sendProtoclo);
            if (m_rt != Errno.OK) {
                System.out.println("send err");
                return m_rt;
            }

            Protocol recvProtocol = new Protocol();
            m_rt = recv(recvProtocol);
            if (m_rt != Errno.OK) {
                System.out.println("recv err");
                return m_rt;
            }

            System.out.println(recvProtocol.getBody());

        } finally {
            close();
        }

        return m_rt;
    }
}
